package sjtu.ist.warehouse4ws.service;

import java.util.List;

import sjtu.ist.warehouse4ws.dao.FunctionsDao;
import sjtu.ist.warehouse4ws.dao.cust.CustFunctionsDao;
import sjtu.ist.warehouse4ws.model.CustFunctions;
import sjtu.ist.warehouse4ws.model.Functions;
import sjtu.ist.warehouse4ws.model.Process;
import sjtu.ist.warehouse4ws.tool.Constants;
import sjtu.ist.warehouse4ws.tool.PropertyHelper;

public class FunctionsServiceImpl implements FunctionsService{

	private FunctionsDao functionsDao;
	private CustFunctionsDao custFunctionsDao;
	
	public void setFunctionsDao(FunctionsDao functionsDao) {
		this.functionsDao = functionsDao;
	}
	
	public void setCustFunctionsDao(CustFunctionsDao custFunctionsDao) {
		this.custFunctionsDao = custFunctionsDao;
	}
	
	public void save(Functions functions, int companyId) {
		// TODO Auto-generated method stub
		if(companyId==Constants.ADMIN_COMPANY_ID){
			functionsDao.sava(functions);
		}else{
			CustFunctions cf=new CustFunctions();
			PropertyHelper.copyProperties(functions, cf);
			custFunctionsDao.save(cf);
		}		
	}
	
	@Override
	public List<Process> getProcessbyFunctionId(String functionId) {
		// TODO Auto-generated method stub
		return functionsDao.getProcessbyFunctionId(functionId);
	}
	@Override
	public List<Functions> getFunctionsbyFunctionId(String functionId) {
		// TODO Auto-generated method stub
		return functionsDao.getFunctionsbyFunctionId(functionId);
	}

}
